import { getUserInfo, getConfig, getMyUserHomeInfo } from '@/api/my.js'
import { getmessage_count } from '@/api/myMessage.js'
export default {
	data() {
		return {
			configInfo: null,
			userInfo: {},
			no_login: require('@/static/img/my/index/no_login.png'),
			majorTypes: '',
			vipInfo: {
				color: '',
				text: '',
				timeColor: ''
			},//vip显示信息
			kongItem: [
				{
					name: '小竹会员',
					iconUrl: require('@/static/img/my/index/icon_vip.png'),
					url: '../vip/index',
					backgroundColor: '#FEF8F3',
				}, {
					name: '小竹叶',
					iconUrl: require('@/static/img/my/index/icon_leaf.png'),
					url: '../bambooLeaf/index',
					backgroundColor: '#F3F9F4',
				}, {
					name: '我的邀请',
					iconUrl: require('@/static/img/my/index/icon_invite.png'),
					url: '../Invite/index',
					backgroundColor: '#F5F8FE',
				}, {
					name: '我的提问',
					iconUrl: require('@/static/img/my/index/icon_quiz.png'),
					url: '../quiz/index',
					backgroundColor: '#FCF8F7',
				}
			],//金刚区
			oftenList: [
				// {
				// 	icon: require('@/static/img/my/index/icon-xxjl.png'),
				// 	name: '学习记录',
				// 	url: '/pages/my/myHome/learningRecord/learningRecord'
				// },
				// {
				// 	icon: require('@/static/img/my/index/icon-sc.png'),
				// 	name: '我的收藏',
				// 	url: '/pages/my/myCollection/index'
				// }, {
				// 	icon: require('@/static/img/my/index/icon-xz.png'),
				// 	name: '我的下载',
				// 	url: '/pages/my/myHome/myDownload/myDownload'
				// }, {
				// 	icon: require('@/static/img/my/index/icon-dd.png'),
				// 	name: '我的订单',
				// 	url: '/pages/my/myHome/myOrders/myOrders',
				// 	handler: ''
				// },
				// {
				// 	icon: require('@/static/img/my/index/coupon_icon.png'),
				// 	name: '我的卡包',
				// 	url: '/pages/my/myHome/coupons/coupons',
				// 	handler: ''
				// },
				// {
				// 	icon: require('@/static/img/my/index/icon-zyrs.png'),
				// 	name: '专业人员',
				// 	url: '/pages/my/major/index',
				// 	handler: 'getMajors'
				// },
				// {
				// 	icon: require('@/static/img/my/index/icon-yjfk.png'),
				// 	name: '意见反馈',
				// 	url: '/pages/my/feedback/index',
				// },
				{
					icon: require('@/static/img/my/index/icon-lxwm.png'),
					name: '联系我们',
					url: '',
					handler: 'WXOpenCustomerServiceChat'
				},
				{
					icon: require('@/static/img/my/index/icon-sz.png'),
					name: '设置',
					url: '/pages/my/settings/index',
				}
			],//常用功能
			majorTypes: '',
			backgroundVipUrl: require('@/static/img/my/index/bj-vip.png'),
		}
	},
	methods: {
		//获取个人信息
		getUserInfo() {
			getUserInfo({}).then(res => {
				let info = res.data
				this.userInfo = info
				this.majorTypes = info.major_types ? info.major_types.replace(/,/g, '、') : ''
				this.showVipInfo(info.is_vip)
				this.kongItem[0].text = info.is_vip >= 1 && info.is_vip <= 6 ? info.vip_end_time_text : '去开通';
				this.kongItem[1].text = info.money
				this.kongItem[2].text = info.team_count
				this.kongItem[3].text = info.quiznum
			})
		},
		//去个人中心
		goMyHome() {
			uni.navigateTo({
				url: '/pages/my/homePage/edit'
			})
		},

		// vip信息处理
		showVipInfo(vip) {
			var text = "";
			var color = "";
			var timeColor = "";

			switch (vip) {
				case 1:
					text = "大会员";
					color = "cDhy";
					timeColor = "cDhy-time";
					break;
				case 2:
				case 3:
					text = "超级会员";
					color = "cCjhy";
					timeColor = "cCjhy-time";
					break;
				case 4:
				case 5:
				case 6:
					text = "竹海会员";
					color = "cQyhy";
					timeColor = "cQyhy-time";
					break;
			}
			let vipInfo = {
				text: text,
				color: color,
				timeColor: timeColor
			}
			this.vipInfo = vipInfo
			// return vipInfo
		},

		//跳转
		jump(e) {
			let url = e.url
			uni.navigateTo({
				url: url
			})
		},

		//常用功能点击
		menuClick(item) {
			if (!uni.getStorageSync("token")) {
				this.getUserInfo()
				return
			}
			if (item.handler) this[item.handler]()
			else if (item.url) this.$used.href(item.url)
		},

		//打开微信客服
		WXOpenCustomerServiceChat() {
			// #ifndef APP-PLUS
			uni.showToast({
				title: '请在app打开',
				icon: "none"
			});
			// #endif
			let wechat = null
			plus.share.getServices(res => {
				wechat = res.find(i => i.id === 'weixin')
				if (wechat) {
					wechat.openCustomerServiceChat({
						corpid: 'ww447880e03d7eba27', //企业ID
						url: 'https://work.weixin.qq.com/kfid/kfc8c70c43a4de355ad', //客服地址
					}, src => {
						console.log("success:", JSON.stringify(src))
					}, err => {
						console.log("error:", JSON.stringify(err))
					})
				} else {
					uni.showToast({
						title: '当前环境不支持微信操作',
						icon: "error"
					});
				}
			}, function () {
				uni.showToast({
					title: "获取服务失败，不支持该操作。" + JSON.stringify(e),
					icon: 'none'
				})
			});
		},

		//获取设置
		getConfigs() {
			getConfig().then(({ code, data, msg }) => {
				if (code == 1) {
					this.configInfo = data;
				} else {
					this.$used.msg(msg)
				}
			})
		},

		getMyUserHomeInfo() {
			getMyUserHomeInfo(({
				code,
				data,
				msg
			}) => {
				if (code == 1) {
					this.majorTypes = data.major_types
				}
			})
		},
		getMessages() {
			getmessage_count({}).then(res => {
				if (res.code == 1) {
					let num = Number(res.data.commentandlike) + Number(res.data.message) + Number(res.data.question)

					if (num > 0)
						uni.setTabBarBadge({
							index: 2,
							text: num > 99 ? '99+' : '' + num
						})
					else
						uni.removeTabBarBadge({
							index: 2
						})
				}
			})
		},

	},
	onShow() {
		this.getConfigs()
		if (uni.getStorageSync("token")) {
			this.userInfo.mobile = '1'
			this.getUserInfo()
			this.getMyUserHomeInfo()
			this.getMessages()
		} else {
			this.userInfo = {}
			this.majorTypes = ''
		}
	},
	onLoad(e) {

	},
}